package exercise;

import JZOffer.Day006_1;
import JZOffer.TreeNode;

import java.util.Arrays;

public class LCR144 {
    public TreeNode mirrorTree(TreeNode root) {
        if (root == null || root.left == null && root.right == null) {
            return root;
        }
        swap(root);
        return root;
    }

    private void swap(TreeNode node) {
        if (node == null) {
            return;
        }

        TreeNode tmp = node.left;
        node.left = node.right;
        node.right = tmp;
        swap(node.left);
        swap(node.right);
    }

    public static void main(String[] args) {
        TreeNode root = new TreeNode(5);
        root.left = new TreeNode(7);
        root.right = new TreeNode(9);
        root.left.left = new TreeNode(8);
        root.left.right = new TreeNode(3);
        root.right.left = new TreeNode(2);
        root.right.right = new TreeNode(4);

        Day006_1 day0061 = new Day006_1();
        System.out.println(Arrays.toString(day0061.levelOrder(root)));

        LCR144 lcr144 = new LCR144();
        lcr144.mirrorTree(root);
        System.out.println(Arrays.toString(day0061.levelOrder(root)));
    }
}
